package com.minimalist.lindi.controller;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.news.LindiNewsQueryVO;
import com.minimalist.common.entity.lindi.vo.news.LindiNewsVO;
import com.minimalist.common.response.R;
import com.minimalist.common.utils.Add;
import com.minimalist.common.utils.Update;
import com.minimalist.lindi.service.LindiNewsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 11987
 */
@Validated
@RestController
@Tag(name = "林地指标交易平台_新闻管理")
@RequestMapping("/lindi/news")
public class LindiNewsController{

    @Autowired
    private LindiNewsService service;

    @PostMapping("/addNews")
    @Operation(summary = "添加新闻")
    public R<?> addNews(@RequestBody @Validated(Add.class) LindiNewsVO newsVO){
        service.addNews(newsVO);
        return R.ok();
    }

    @DeleteMapping("/deleteNewsByNewsId")
    @Operation(summary = "删除新闻 -> 根据新闻ID删除")
    public R<?> deleteNewsByNewsId(
            @RequestParam("newsId")
            @NotNull(message = "新闻ID不能为空")
            @Parameter(name = "newsId", required = true, description = "新闻ID")
            Long newsId){
        service.deleteNewsByNewsId(newsId);
        return R.ok();
    }

    @PutMapping("/updateNewsByNewsId")
    @Operation(summary = "修改新闻")
    public R<?> updateNewsByNewsId(
            @RequestBody @Validated(Update.class) LindiNewsVO newsVO){
        service.updateNewsByNewsId(newsVO);
        return R.ok();
    }

    @GetMapping("/getPageNewsList")
    @Operation(summary = "查询新闻列表(分页)")
    public R<PageResp<LindiNewsVO>> getPageNewsList(@RequestBody LindiNewsQueryVO queryVO){
        return R.ok(service.getPageNewsList(queryVO));
    }

    @GetMapping("/getNewsByNewsId/{newsId}")
    @Operation(summary = "根据新闻ID查询新闻")
    public R<LindiNewsVO> getNewsByNewsId(
            @PathVariable(value = "newsId")
            @NotNull(message = "新闻ID不能为空")
            @Parameter(name = "newsId", description = "参数ID", required = true)
            Long newsId){
        return R.ok(service.getNewsByNewsId(newsId));
    }
}